import { mapGetters } from 'vuex';
const districtOptionsMixin = {
  data() {
    return {
      userAdName: '', // 当前用户所在区县名称
    }
  },
  computed: {
    ...mapGetters(['district', 'userAdCd']),
    // 除重庆市外，其它区县只显示自己的区县选项
    districtOptions() {
      let { district, userAdCd } = this;
      if (userAdCd === '') {
        return district
      }

      if (userAdCd === '500000') {
        this.setUserAdName('重庆市')
        return district
      }

      let findCurrentDistrict = district.find(item => item.adCd === userAdCd);
      if (findCurrentDistrict) {
        this.setUserAdName(findCurrentDistrict.adNm)
        return [findCurrentDistrict]
      } else {
        return []
      }
    }
  },
  methods: {
    setUserAdName(adNm) {
      this.userAdName = adNm
    }
  },
}

export { districtOptionsMixin }